<?
session_start();
//error_reporting(E_ALL);
include('conn.php');

$q = $_REQUEST["q"];
if($q == '1')
{
	$qry1 = "SELECT societyname from society where status='1' order by societyname;";
	$qry = mysql_query($qry1);	
	
	while($rows = mysql_fetch_array($qry))
	{		
		$data[] = array(			
			"n"=>$rows['societyname']
			);		
	}
	echo json_encode($data);
}
else if($q=='2')
{	
	$qry1 = "SELECT SAFno from Customer where status='1';";
	$qry = mysql_query($qry1);	
	
	while($rows = mysql_fetch_array($qry))
	{		
		$data[] = array(			
			"saf" => $rows['SAFno']
			);		
	}
	echo json_encode($data);
	
}
else{
	$qrysel = "SELECT * from Customer where status='1' order by CustId desc;";
	$ressel = mysql_query($qrysel);	
	$data = array();
	
	while($rows = mysql_fetch_array($ressel))
	{		
		$sid = $rows['socId'];
		$qry5 = "select societyname from society where status='1' and socid='$sid';";
		$res5 = mysql_query($qry5);
		$row5 = mysql_fetch_array($res5);
		$sname = $row5["societyname"];
		
		$data[] = array
			(			
				"id" => $rows['CustId'],
				"socId" => $rows['socId'],
				"saf" => $rows['SAFno'],
				"soc" => $sname,
				"room" => $rows['RoomNumber'],
				"floor" => $rows['Floor'],
				"fname" => $rows['firstname'],
				"mname" => $rows['middlename'],
				"lname" => $rows['lastname'],
				"email" => $rows['Email'],
				"phone" => $rows['TelNo'],				
				"actdt" => $rows['dateofactivation'],
				"termdt" => $rows['dateoftermination'],
				"note" => $rows['Notes']
			);
	}
	echo json_encode($data);
}
?>